import type { Options } from '@/try-on/config'
export class GetCameraStream {
  constructor(videoElement: HTMLVideoElement, options: Options) {
    navigator.mediaDevices
      .getUserMedia({ video: true })
      .then((stream) => {
        // const track = stream.getVideoTracks()
        // const videoStream = new MediaStream()
        // videoStream.addTrack(track[0])
        videoElement.srcObject = stream
        videoElement.muted = true
        // videoElement.autoplay = true
        // videoElement.pause()
        videoElement.play()
        videoElement.controls = true
        videoElement.style.width = '200px'
        if (options.videoAppend) {
          const appendContainer = document.querySelector(options.videoAppend)

          appendContainer?.appendChild(videoElement)
        }
        // document.body.appendChild(videoElement)
      })
      .catch(() => {
        alert('未发现摄像头')
        window.close()
      })
  }
}
